package com.education.cms.config;

import com.education.cms.filter.AdminFilter;
import com.education.cms.filter.LoginFilter;
import com.education.cms.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class FilterConfig {
    @Autowired
    private RedisUtils redisUtils;
    @Bean
    public FilterRegistrationBean filterLoginRegistration(){
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new LoginFilter(redisUtils));
        Map<String,String> initParameters=new HashMap<>(10);
        initParameters.put("ignoreURL","/login");
        registration.setInitParameters(initParameters);
        registration.addUrlPatterns("/*");
        registration.setName("loginFilter");
        registration.setOrder(1);
        return registration;
    }

    @Bean
    public FilterRegistrationBean filterAdminRegistrationBean(){
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new AdminFilter(redisUtils));
        Map<String,String> initParameters = new HashMap<>(10);
        initParameters.put("ignoreURL","/login");
        registration.setInitParameters(initParameters);
        registration.addUrlPatterns("/*");  //此处日后在修改
        registration.setName("adminFilter");
        registration.setOrder(2);
        return registration;
    }
}
